package com.hantanger.weblog.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import redstone.xmlrpc.XmlRpcServer;

import com.hantanger.weblog.xmlrpc.handler.MetaWeblogHandler;

/**
 * xml-rpc服务
 * @author lys
 *
 */
public class XmlRpcController extends BaseController {
	
	/** The XmlRpcServer containing the handlers and processors. */
    private XmlRpcServer server;
    
    public XmlRpcController(){
    	server = new XmlRpcServer();
    	MetaWeblogHandler metaWeblog = new MetaWeblogHandler();
    	server.addInvocationHandler("metaWeblog", metaWeblog);
    	server.addInvocationHandler("blogger", metaWeblog);
    }
	
	@Override
	public String doGet(HttpServletRequest request, HttpServletResponse response) {
		response.setContentType(XML);
		try {
			server.execute(request.getInputStream(), response.getWriter());
			response.getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
